home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / ab20_archive / utilities / printer / pf_deskjet.lzh / PF / Source / umain.c < prev    next >
C/C++ Source or Header  |  1991-09-27  |  5KB  |  188 lines

  1. /*      _main.c         Copyright (C) 1985  Lattice, Inc.
  2. *       Hacked by MLO, for PF2.c
  3. */
  4.  
  5. #define OUT_WINDOW_MAX_HT   150         /* Maximum allowed window height */
  6.  
  7. #include <stdio.h>                      /* Standard library */
  8. #include <fcntl.h>
  9. #include <ios1.h>
  10. #include <stdlib.h>
  11. #include <exec/types.h>                 /* Amiga specific */
  12. #include <intuition/intuition.h>
  13. #include <intuition/intuitionbase.h>
  14. #include <workbench/startup.h>
  15. #include <libraries/dos.h>
  16. #include <libraries/dosextens.h>
  17. #include <devices/printer.h>
  18. #include <proto/exec.h>
  19. #include <proto/intuition.h>
  20. #include <proto/dos.h>
  21. #include "pf2.h"                        /* Program specific */
  22.  
  23. #define MAXARG 32                       /* maximum command line arguments */
  24. #define QUOTE  '"'
  25. #define ESCAPE '*'
  26. #define NL '\n'
  27.  
  28. #define isspace(c)            ((c == ' ') || (c == '\t') || (c == '\n'))
  29.  
  30. extern int _fmode;
  31. extern int (*_ONBREAK)();
  32.  
  33. int CXBRK(void);
  34.  
  35. extern struct UFB _ufbs[];
  36. static int argc = 0;                    /* arg count */
  37. static char **targv, *argv[MAXARG];     /* arg pointers */
  38.  
  39. #define MAXWINDOW 40
  40. extern struct WBStartup *WBenchMsg;
  41.  
  42. /*
  43. *
  44. * name         _main - process command line, open files, and call "main"
  45. *
  46. * synopsis     _main(line);
  47. *              char *line;     ptr to command line that caused execution
  48. *
  49. * description   This function performs the standard pre-processing for
  50. *               the main module of a C program.  It accepts a command
  51. *               line of the form
  52. *
  53. *                       pgmname arg1 arg2 ...
  54. *
  55. *               and builds a list of pointers to each argument.  The first
  56. *               pointer is to the program name.  For some environments, the
  57. *               standard I/O files are also opened, using file names that
  58. *               were set up by the OS interface module XCMAIN.
  59. *
  60. */
  61.  
  62. void _main(
  63.   register char *line
  64. ){
  65.   register char **pargv;
  66.   register int x;
  67.   struct Process *process;
  68.   struct FileHandle *handle;
  69.   static char window[MAXWINDOW+18];
  70.   char *argbuf;
  71.  
  72. /*
  73. * Build argument pointer list
  74. */
  75.  
  76.   while (argc < MAXARG) {
  77.     while (isspace(*line))      line++;
  78.     if (*line == '\0')          break;
  79.     pargv = &argv[argc++];
  80.     if (*line == QUOTE) {
  81.       argbuf = *pargv = ++line;       /* ptr inside quoted string */
  82.       while (*line != QUOTE) {
  83.         if (*line == ESCAPE) {
  84.           line++;
  85.           switch (*line) {
  86.             case 'E':
  87.               *argbuf++ = ESC;
  88.               break;
  89.             case 'N':
  90.               *argbuf++ = NL;
  91.               break;
  92.             default:
  93.               *argbuf++ = *line;
  94.           }
  95.           line++;
  96.         } else {
  97.           *argbuf++ = *line++;
  98.         }
  99.       }
  100.       line++;
  101.       *argbuf++ = '\0';               /* terminate arg */
  102.     } else {
  103.       *pargv = line;                  /* non-quoted arg */
  104.       while ((*line != '\0')   &&   (!isspace(*line)))      line++;
  105.       if (*line == '\0')  break;
  106.          else *line++ = '\0';         /* terminate arg */
  107.     }
  108.   }  /* while */
  109.   targv = (argc == 0) ? (char **) WBenchMsg : (char **) &argv[0];
  110.  
  111.  
  112. /*
  113. * Open standard files
  114. */
  115.  
  116.   if (argc == 0) {                    /* running under workbench */
  117.     long lock;
  118.     int sWidth, sHeight;
  119.  
  120. /*
  121. * Open intuition library
  122. */
  123.  
  124.     IntuitionBase = LibOpen("intuition.library", REVISION);
  125.     lock = LockIBase(0);
  126.     sWidth = IntuitionBase->ActiveScreen->Width;
  127.     sHeight = IntuitionBase->ActiveScreen->Height;
  128.     UnlockIBase(lock);
  129.  
  130.     if (sHeight > OUT_WINDOW_MAX_HT)  sHeight = OUT_WINDOW_MAX_HT;
  131.     sprintf(window, "Con:0/0/%d/%d/\"PF2\" - v%.2f - MLO %ld ",
  132.             sWidth, sHeight, VERSION, LAST_CHANGE);
  133.  
  134.     _ufbs[0].ufbfh = Open(window,MODE_NEWFILE);
  135.     _ufbs[1].ufbfh = _ufbs[0].ufbfh;
  136.     _ufbs[1].ufbflg = UFB_NC;
  137.     _ufbs[2].ufbfh = _ufbs[0].ufbfh;
  138.     _ufbs[2].ufbflg = UFB_NC;
  139.     handle = (struct FileHandle *) (_ufbs[0].ufbfh << 2);
  140.     process = (struct Process *) FindTask(NULL);
  141.     process->pr_ConsoleTask = (APTR) handle->fh_Type;
  142.     x = 0;
  143.   } else {
  144.     _ufbs[0].ufbfh = Input();         /* running under CLI */
  145.     _ufbs[1].ufbfh = Output();
  146.     _ufbs[2].ufbfh = Open("*", MODE_OLDFILE);
  147.     x = UFB_NC;                       /* do not close CLI defaults */
  148.   }
  149.  
  150.   _ufbs[0].ufbflg |= UFB_RA | O_RAW | x;
  151.   _ufbs[1].ufbflg |= UFB_WA | O_RAW | x;
  152.   _ufbs[2].ufbflg |= UFB_RA | UFB_WA | O_RAW;
  153.  
  154.   x = (_fmode) ? 0 : _IOXLAT;
  155.   stdin->_file = 0;
  156.   stdin->_flag = _IOREAD | x;
  157.   stdout->_file = 1;
  158.   stdout->_flag = _IOWRT | x;
  159.   stderr->_file = 2;
  160.   stderr->_flag = _IORW | x;
  161.  
  162. /*
  163. * Establish control-c handler
  164. */
  165.  
  166.   _ONBREAK = CXBRK;
  167.  
  168. /*
  169. * Print program header (if from CLI)
  170. **/
  171.  
  172.   if (argc) fprintf(stdout, "\n\t\"PF2\" - v%.2f - MLO %d\n\n",
  173.             VERSION, LAST_CHANGE);
  174.  
  175. /*
  176. * Call user's main program
  177. */
  178.  
  179.   main(argc, targv);                  /* call main function */
  180.   exit(0);
  181. }
  182.  
  183. /*
  184. * Disable SAS Control-C built-in handling.
  185. */
  186.  
  187. int CXBRK(void)           { return 0; }
  188.